package com.prs.crm.dao.oa.impl;

import java.util.Collection;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.dao.oa.VehicleInsuranceTypeDao;
import com.prs.crm.domain.meeting.MeetSource;
import com.prs.crm.domain.oa.RegulationType;
import com.prs.crm.domain.oa.VehicleInsuranceType;

public class VehicleInsuranceTypeDaoImpl extends BaseDaoImpl<VehicleInsuranceType> implements VehicleInsuranceTypeDao{

	@Override
	public List<VehicleInsuranceType> getAllType() {
		Criteria criteria = this.getSession().createCriteria(VehicleInsuranceType.class);
		List<VehicleInsuranceType> list = criteria.list();
		if(list.size()!=0){
			return list;
		}else{
			return null;
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public Collection<VehicleInsuranceType> getRootVehicleInsuranceTypes() {
		return (Collection<VehicleInsuranceType>)this.getHibernateTemplate().execute(
				new HibernateCallback()
				{
					public Object doInHibernate(Session session) throws HibernateException {
			        	Criteria criteria = session.createCriteria(VehicleInsuranceType.class);
			        	criteria.add(Restrictions.isNull("parent"));
			        	criteria.addOrder(Order.asc("id"));
			        	return criteria.list();
			        }   
				}
		);
	}

}
